<?php  
 
namespace Common\Provider; 
use Common\Util\ConfigUtils; 
/**
 * 支付提供商
 * @author liuyang
 * @since 20160417
 * @version 2.0
 */  
class PayProvider{  
     /**
        签名
      */
    public static function sign($paytype,$data){
       //信息签名
         $payService = null;
         $config = array();  
         $config = ConfigUtils::getConfig($paytype);  
         if($config != null){
            // echo $config['SIGN_SERVICE'];exit();
            //通过Common/Conf/pay.conf加载支付类
             $payServiceClass =  new \ReflectionClass($config['SIGN_SERVICE']);  
             $payService=$payServiceClass->newInstanceArgs(); 
             //查询是不是还要加载其他的POST字段
             $extraField = $config['EXTRA_FIELD'];
             if($extraField != null){
                 $fieldlist = explode(",", $extraField);
                 foreach($fieldlist as $key){
                     $data[$key]=$_REQUEST[$key];
                 }
             } 
       $info=$payService->getSignInfo($data, $config); 
       return $info;
    }
   }
   /*
    * 回调
    */
   public static function nofity($paytype,$callback){
       $payList = ConfigUtils::getConfig("PAY_LIST");
       if(in_array($paytype, $payList)){
           $config = ConfigUtils::getConfig($paytype);
           if($config != null){
               //Common/Conf/pay.conf
               $payServiceClass =  new \ReflectionClass($config['NOTIFY_SERVICE']);
               $notifyService=$payServiceClass->newInstanceArgs(array($config));
               $notifyService->notify(function($data) use ($callback){   
                   return call_user_func($callback,$data);
               });
           }
       }else{
           echo "不存在支付方式";
       }
   }
}

?>